{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('FedMF-Full.txt', 'r', encoding='utf-8') as f:\n",
    "    fedmf_full = f.readlines()\n",
    "with open('FedMF-Part.txt', 'r', encoding='utf-8') as f:\n",
    "    fedmf_part = f.readlines()\n",
    "with open('MF.txt', 'r', encoding='utf-8') as f:\n",
    "    mf = f.readlines()\n",
    "    \n",
    "fedmf_full = [e.strip('\\n') for e in fedmf_full if e.startswith('loss')]\n",
    "fedmf_full = [float(e.split(' ')[-1]) for e in fedmf_full]\n",
    "\n",
    "fedmf_part = [e.strip('\\n') for e in fedmf_part if e.startswith('loss')]\n",
    "fedmf_part = [float(e.split(' ')[-1]) for e in fedmf_part]\n",
    "\n",
    "mf = [e.strip('\\n') for e in mf if e.startswith('loss')]\n",
    "mf = [float(e.split(' ')[-1]) for e in mf]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig, axs = plt.subplots()\n",
    "\n",
    "axs.plot(fedmf_full, 'b+-', label='FedMF-Full', linewidth=0.5)\n",
    "axs.plot(fedmf_part, 'g.-', label='FedMF-Part', linewidth=0.5)\n",
    "axs.plot(mf, 'r-', label='Regular-MF', linewidth=0.5)\n",
    "\n",
    "axs.grid()\n",
    "axs.legend(fontsize=15)\n",
    "\n",
    "axs.set_xlabel('Epochs', fontsize=15)\n",
    "axs.set_ylabel('Train Loss', fontsize=15)\n",
    "\n",
    "fig.set_size_inches(10, 5)\n",
    "fig.savefig('%s.png' % 'comparison', dpi=100)\n",
    "plt.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
